"""
求函数 f(x) = atan(1/x) 在 x = 0 处的左右极限值
"""

import plotly.graph_objects as go
import numpy as np
import sympy as sp

# 定义变量
x = sp.symbols("x")
# 定义函数
f = sp.atan(1 / x)

# x=0 左极限
limit_left = sp.limit(f, x, 0, dir="-")
# x=0 右极限
limit_right = sp.limit(f, x, 0, dir="+")
print(f"函数 f(x)=atan(1/x) x=0 左极限值: {limit_left}, 右极限值: {limit_right}")


# 可视化显示
x_values = np.linspace(-np.pi, np.pi, 200)
y_values = np.atan(1 / x_values)

fig = go.Figure(data=go.Scatter(x=x_values, y=y_values, mode="lines"))
# 更新布局
fig.update_layout(
    title="f(x)=atan(1/x) x=0 左极限值",
    xaxis=dict(
        tickmode="array",
        tickvals=[-np.pi, -np.pi / 2, 0, np.pi / 2, np.pi],
        ticktext=["-π", "-π/2", "0", "π/2", "π"],
    ),
)
fig.show()
